i found this error in other places but not with RSS feed.. so anyway, i'm trying to create a news app with react native using RSS feeds.. i got this one from "huffpost", was mainly logging on the browser (since it's the easier for me to use), i did fetch the data from the RSS feed, parsed it:
const getNews = async () => {
fetch('https://peaceful-peak-58941.herokuapp.com/https://www.huffpost.com/section/front-page/feed?x=1')
.then((response) => response.text())
.then((responseData) => rssParser.parse(responseData))
.then((rss) => {
setArticles(rss.items)
});
}
when i logged it i noticed that it logs twice, once when the state is still empty (still didn't get any feed yet), then the 2nd time is when i get the feed nd the data i need, i was like thats fine since it happened to me before in reactJs but it was "fine" at the time, now i was like okay let me try this on a mobile emulator.. but then instead of it just doing the same thing as in the browser, it just keeps giving me the error "possible unhandled promise rejection: "Unable to find any RSS element in feed" ", why doesn't it display the data since eventually it should get the data? (i tried again on the browser nd it seems to work) (using expo if it matters)
{articles.length > 0 ? articles.map(article=>(
<View key={article.id} style={{width:"100%"}}>
<Text style={styles.title}>{article.title}</Text>
<Image style={{width:'100%', height:"300px"}}
source={{uri:`${article.enclosures[0].url}`}}/>
<Text style={styles.description}>{article.description}</Text>
</View>
)) : <Text>...</Text>}
Fetch will recieve OPTIONS first and send the actual data right after that. You can configure it so you can fetch without the annoying OPTIONS. Just add another parameter {method: 'get'}, in the fetch function
const getNews = async () => {
fetch('https://peaceful-peak-58941.herokuapp.com/https://www.huffpost.com/section/front-page/feed?x=1', {method:'get'})
.then((response) => response.text())
.then((responseData) => rssParser.parse(responseData))
.then((rss) => {
setArticles(rss.items)
});
}